package com.itheima.threadpool_demo;
/*
    CAS + 自旋   :   乐观锁
    synchronized :  悲观所
    原子类
 */
public class Test5 {
    public static void main(String[] args) throws InterruptedException {
        Money m = new Money();

        new Thread(new Runnable() {
            @Override
            public void run() {
                while (m.money == 100) {
                    // 死循环
                }
                System.out.println("循环结束");
            }
        }, "A").start();

        Thread.sleep(3000);

        new Thread(new Runnable() {
            @Override
            public void run() {
                m.money = 200;
            }
        }, "B").start();
    }
}

class Money {
    // public  int money = 100;// 200
    // volatile : 强制线程在使用此变量时 , 跟新堆内存中变量数据值
    public volatile int money = 100;// 200
}


